package com.jinken.controller;

import com.jinken.domain.AlarmMessageDto;
import com.jinken.service.ISendMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SkyWalkingAlarmController {

    @Autowired
    private ISendMessageService sendMessageService;


    @RequestMapping("/alarm")
    public void alarm(@RequestBody List<AlarmMessageDto> messages) throws Exception {

        for (AlarmMessageDto message : messages) {
            System.out.println("message = " + message);
            /**
             * AlarmMessageDto(scopeId=1, scope=SERVICE, name=user-service,
             * id0=dXNlci1zZXJ2aWNl.1, id1=, ruleName=service_response_time_rule,
             * alarmMessage=服务user-service最近1分钟以内响应时间超过了1ms, tags=[],
             * startTime=1718784442355, period=0, onlyAsCondition=false)
             */
            //TODO 发送短信，发送邮件
            sendMessageService.sendMessage("19876850907",1232);

        }

    }
}
